#pragma once

#include "PointSet.h"

/*
* The bin query class of the PointSet family
* A tree division of the bounded space
*
* author:	Yanbo Li
* date:		Jan. 13rd 2015
*/
class BinQuery :
	public PointSet
{
private:
	class Bin
	{
	public:
		unsigned int key_level;
		double key_delta;
		double* key_min;
		double* key_max;
		unsigned int key_dimension;
		unsigned int count;
	public:
		std::vector<Bin*>* sections;
		std::vector<double*>* keys;
		std::vector<void*>* objects;
	public:
		Bin();
		~Bin();
	public:
		void add_point(double* key, void* object);
	public:
		void range_exclusive_traversal(double* key, double range, std::vector<double*>*& coords, std::vector<void*>*& objects);
	};

protected:
	void construct_bin_structure(Bin* bin);
	Bin* root;
	
public:
	unsigned int division_depth;
	unsigned int* division;

	unsigned int n_bins;

public:
	BinQuery(unsigned int dimension, double* coord_max, double* coord_min, unsigned int division_depth, unsigned int* division);
	~BinQuery();
	void validation_initialization();
	void add_point(double* key, void* object);
	void nearest_neighbor(double* key, double range, std::vector<double*>*& coords, std::vector<void*>*& results);
};

